home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SetWindBackColor.c
-
- Contains: Demonstrates how to programmatically set the background color of a window
- without flicker.
-
- Written by: Pete Gontier
-
- Copyright: Copyright © 1997-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 8/9/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
- #include <Sound.h>
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #ifndef __FONTS__
- # include <Fonts.h>
- #endif
-
- #ifndef __DIALOGS__
- # include <Dialogs.h>
- #endif
-
- #ifndef __QDOFFSCREEN__
- # include <QDOffscreen.h>
- #endif
-
- static pascal OSErr InitMac (void)
- {
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return noErr;
- }
-
- static pascal Boolean SetColorTableEntry (CTabHandle cth, short value, const RGBColor *rgbP)
- {
- ColorSpecPtr ctTable = (**cth).ctTable;
- short ctSize = (**cth).ctSize;
-
- while (ctSize > -1)
- {
- if (ctTable->value == value)
- {
- ctTable->rgb = *rgbP;
- CTabChanged (cth);
- return true;
- }
-
- ++ctTable;
- --ctSize;
- }
-
- return false;
- }
-
- void main (void)
- {
- if (InitMac ( ))
- SysBeep (10);
- else
- {
- WindowRef window;
- Rect boundsRect = qd.screenBits.bounds;
-
- //
- // [1] Create a window which covers most of the main screen.
- // Make it invisible for now.
- //
- // [2] Get the window's color table.
- //
- // [3] 'winCTabHandle' is the default color table because we've
- // just now created the window out of thin air. We don't want
- // to change the default color table, so make a copy.
- //
- // [4] Set the background entry (0) of the color table.
- //
- // [5] Set the window's color table.
- //
- // [6] Up till now, none of the changes we've made have been
- // visible. That's the way we've wanted it because the whole
- // purpose here is to avoid visible changes, which result in
- // flicker.
- //
- // [7] Wait for the user to click,
- // then put a smart-aleck message in the debugger.
- //
-
- InsetRect (&boundsRect,10,10); // 1
- boundsRect.top += GetMBarHeight ( ); // 1
- window = NewCWindow (nil,&boundsRect,"\p",false,plainDBox,(WindowRef)-1,false,0); // 1
- if (window) // 1
- {
- WCTabHandle winCTabHandle; // 2
- AuxWinHandle auxWinHandle; // 2
-
- GetAuxWin (window,&auxWinHandle); // 2
- winCTabHandle = (WCTabHandle) ((**auxWinHandle).awCTable); // 2
-
- HandToHand ((Handle *) &winCTabHandle); // 3
- if (!MemError ( )) // 3
- {
- RGBColor blackness = { 0, 0, 0 }; // 4
-
- if (SetColorTableEntry ((CTabHandle) winCTabHandle, 0, &blackness)) // 4
- {
- SetWinColor (window,winCTabHandle); // 5
-
- ShowWindow (window); // 6
-
- while (!Button ( )) ; // 7
- DebugStr ("\pNotice any flicker? I thought not."); // 7
- }
- }
- DisposeWindow (window);
- }
- }
- }
-